// 1.抓取页面
// 2.解析页面
const request = require("superagent");
require("superagent-charset")(request);
const cheerio = require("cheerio");




async function show() {

    let url = "https://movie.douban.com/top250";
    let res = await request.get(url).charset("UTF-8");
    let html = res.text;
    let $ = cheerio.load(html, {
        decodeEntities: false   //配置这个参数为false就不会出现中文乱码的情况
    });
    let lis = $("#content .item");
    let arr = [];
    lis.each(function (index, value) {
        let imgurl = $(value).find(".pic img").attr("src");
        let title = $(value).find(".pic img").attr("alt");
        let rating = $(value).find(".rating_num").html();
        arr.push({
            imgurl: imgurl,
            title: title,
            rating: rating
        })
    })
    return arr;
}
module.exports = show;